//
//  XWHButtonTBCell.swift
//  XiaoweHearingAid
//
//  Created by Riven on 2022/8/23.
//

import UIKit

class XWHButtonTBCell: UITableViewCell {
    
    lazy var button = UIButton()
    
    var clickCallback: (() -> ())?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = .white
        selectionStyle = .none
        
        addSubViews()
        relayoutSubViews()
    }
    
    required init?(coder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
        super.init(coder: coder)
    }
    
    func addSubViews() {
        contentView.addSubview(button)
        
        button.titleLabel?.font = AppFont.harmonyOSSans(ofSize: 22, weight: .medium)
        button.setTitleColor(UIColor(hex: 0xffffff), for: .normal)
        button.layer.backgroundColor = btnBgColor.cgColor
        button.layer.cornerRadius = 27
        
        button.addTarget(self, action: #selector(clickButton), for: .touchUpInside)
    }
    
    func relayoutSubViews() {
        relayoutSubViews(leftRightInset: 0, bottomInset: 0, height: 54)
    }

    final func relayoutSubViews(leftRightInset: CGFloat = 0, bottomInset: CGFloat = 0, height: CGFloat = 54) {
        button.snp.remakeConstraints { make in
            make.left.right.equalToSuperview().inset(leftRightInset)
            make.height.equalTo(height)
            make.bottom.equalToSuperview().inset(bottomInset)
        }
    }
    
    @objc func clickButton() {
        clickCallback?()
    }

}
